package org.gd.hellojavacore.serial;

import java.io.*;

public class Main {

    public static void main(String...a) throws IOException, ClassNotFoundException {

        OutputStream fos = new FileOutputStream("temp.out");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(new NamedClassImpl1("NamedClassImpl1", "val1"));
        oos.writeObject(new NamedClassImpl2("NamedClassImpl2", "val2"));
        oos.flush();
        oos.close();

        InputStream fis = new FileInputStream("temp.out");
        ObjectInputStream oin = new ObjectInputStream(fis);
        NamedClass ts1 = (NamedClass) oin.readObject();
        NamedClass ts2 = (NamedClass) oin.readObject();
        System.out.printf("name = %s : %s\n", ts1.getName(), ts2.getName());
        System.out.printf("value = %s : %s\n", ts1.getValue(), ts2.getValue());
    }
}
